package com.lhh.entity;

/**
 * @author 李洪豪
 * @Sno 20220301044
 */
public class Result<T> {
    private String code;//状态码
    private String msg;//状态信息
    private T data;//表示从前端接收到的信息封装成data

    public Result(T data) {
        this.data = data;
    }
    public Result(){}
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    //编写方法，不返回json数据，返回需要的Result对象-表示成功时返回的
    public static Result success(){
        Result result = new Result<>();
        result.setCode("200");
        result.setMsg("success");
        return result;
    }
    // 编写方法，可携带自定义数据(返回json数据)，返回需要的Result对象-表示成功时返回的
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>(data);
        result.setCode("200");
        result.setMsg("success");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> success(String msg,T data){
        Result<T> result = new Result<>(data);
        result.setCode("200");
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    //编写方法，可携带自定义数据(返回json数据)，返回需要的Result对象-表示失败时返回的
    public static <T> Result<T> error(String code,String msg){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
